package org.fin.framework.example.service.impl;

import org.fin.framework.example.dao.AccountDao;
import org.fin.framework.example.pojo.Account;
import org.fin.framework.example.service.TransferService;
import org.fin.framework.ioc.annotation.Autowired;
import org.fin.framework.ioc.annotation.Service;
import org.fin.framework.ioc.annotation.Transactional;

/**
 * @author 应癫
 */
@Transactional
@Service
public class TransferServiceImpl implements TransferService {

  @Autowired
  private AccountDao accountDao;


  @Override
  public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

      Account from = accountDao.queryAccountByCardNo(fromCardNo);
      Account to = accountDao.queryAccountByCardNo(toCardNo);

      from.setMoney(from.getMoney()-money);
      to.setMoney(to.getMoney()+money);

      accountDao.updateAccountByCardNo(to);
      int c = 1/0;
      accountDao.updateAccountByCardNo(from);


  }
}
